package thesis.filesharing.common.util;

import thesis.filesharing.resources.Constants;

public class Utils {
	
	public static String insertSignChar(String str) {
		str = str.trim();
		StringBuilder builder = new StringBuilder(str);
		int len = 2 * (str.length() - 1);
		for (int i = 1; i < len; i += 2) {
			builder.insert(i, "|");
		}
		return builder.toString();
	}
	
	public static String removeSignChar(String str) {
		str = str.trim();
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) != '|') {
				builder.append(str.charAt(i));
			}
		}
		return builder.toString();
	}
	
	public static String filterVietnameseSign(String str) {
		String[] VIETNAMESE_SIGN = Constants.VIETNAMESE_SIGN;
		str = str.toLowerCase();
		for (int i = 1; i < VIETNAMESE_SIGN.length; i++) {
			for (int j = 0; j < VIETNAMESE_SIGN[i].length(); j++) {
				str = str.replace(VIETNAMESE_SIGN[i].charAt(j), VIETNAMESE_SIGN[0].charAt(i - 1));
			}
		}
		str = str.replace("\\", "");
		return str;
	}
	
	public static Integer getNextSemesterName(Integer currentSemester) {
		String currSemester = String.valueOf(currentSemester);
		int len = currSemester.length();
		Integer year = Integer.parseInt(currSemester.substring(0, len - 1));
		Integer s = Integer.parseInt(currSemester.substring(len - 1, len));
		
		String str = "";
		if (s < 2) {
			str += String.valueOf(year) + "2";
		} else {
			str += String.valueOf(year + 1) + "1";
		}
		
		return Integer.parseInt(str);
	}
}
